import java.util.*;

/**
 * Created by Administrator on 2015/10/9.
 */

class TableSheet {
    private List<Struct> rowList = null;
    private Map<Integer, Struct> rowMap = null;
    private Struct struct = null;

    public TableSheet(Struct struct) {
        this.rowList = new ArrayList<>();
        this.rowMap = new HashMap<>();
        this.struct = struct;
    }

    public List<Struct> getRowList() {
        return this.rowList;
    }

    public Struct getStruct() {
        return struct;
    }

    public boolean addRow(Struct row) {
        this.rowList.add(row);
        Integer key = Integer.valueOf(row.getKeyField().getValue());
        this.rowMap.put(key, row);
        return true;
    }
}

public class TableSheetMgr {
    private TableSheetMgr() {
    }

    private static TableSheetMgr instance = null;
    private List<TableSheet> sheetList;

    public static TableSheetMgr getInstance() {
        if (instance == null) {
            instance = new TableSheetMgr();
        }
        return instance;
    }

    TableSheet getTableSheet(String name) {
        if (sheetList == null) {
            return null;
        }
        Iterator<TableSheet> it = sheetList.iterator();
        while (it.hasNext()) {
            TableSheet sheet = it.next();
            if (sheet.getStruct().getName() == name) {
                return sheet;
            }
        }
        return null;
    }

    boolean addTableSheet(TableSheet sheet) {
        if (getTableSheet(sheet.getStruct().getName()) != null) {
            return false;
        }

        if (this.sheetList == null) {
            this.sheetList = new ArrayList<>();
        }

        this.sheetList.add(sheet);
        return true;
    }

    List<TableSheet> getSheetList() {
        return this.sheetList;
    }
}
